package ylesanded.kimpExample;

import java.awt.Graphics;
import java.awt.Point;

class Rectangle extends Shape {
	public Point start;
	public Point end;
	
	public Rectangle() {
		
	}

	public Rectangle(Point p) {
		start = p;
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		Point upperLeft = new Point(
				Math.min(start.x, end.x),
				Math.min(start.y, end.y));
		int width = Math.abs(start.x - end.x);
		int height = Math.abs(start.y - end.y);
		
		g.drawRect(upperLeft.x, upperLeft.y, width, height);
	}

	@Override
	public Rectangle copy() {
		Rectangle r = new Rectangle();
		copyHelper(r);
		r.start = new Point(start.x, start.y);
		r.end = new Point(end.x, end.y);
		return r;
	}

	@Override
	public void draw(Point p) {
		end = p;			
	}

	@Override
	public int getDistance(Point p) {
		int d1 = (int) p.distance(start);
//		System.out.println(d1);
		int d2 = (int) p.distance(end);
		return Math.min(d1, d2);
	}

	@Override
	public void move(int dx, int dy) {
		start.x += dx;
		start.y += dy;
		end.x += dx;
		end.y += dy;
	}
	
	
	
}